// 1. 创建一个表达式接口
interface Expression {
    interpret: (context: string) => boolean;
  }
  
  // 2. 创建一个解释器实现类
  class TerminalExpression implements Expression {
    private data: string;
  
    constructor(data: string) {
      this.data = data;
    }
  
    public interpret(context: string): boolean {
      return context.includes(this.data);
    }
  }
  
  class OrExpression implements Expression {
    private expr1: Expression;
    private expr2: Expression;
  
    constructor(expr1: Expression, expr2: Expression) {
      this.expr1 = expr1;
      this.expr2 = expr2;
    }
  
    public interpret(context: string): boolean {
      return this.expr1.interpret(context) || this.expr2.interpret(context);
    }
  }
  
  class AndExpression implements Expression {
    private expr1: Expression;
    private expr2: Expression;
  
    constructor(expr1: Expression, expr2: Expression) {
      this.expr1 = expr1;
      this.expr2 = expr2;
    }
  
    public interpret(context: string): boolean {
      return this.expr1.interpret(context) && this.expr2.interpret(context);
    }
  }
  
  // 3. 使用 Expression 类来创建规则并解析它们
  const robert: Expression = new TerminalExpression("Robert");
  const john: Expression = new TerminalExpression("John");
  const julie: Expression = new TerminalExpression("Julie");
  const marrie: Expression = new TerminalExpression("Marrie");
  
  const isSingle: Expression = new OrExpression(robert, john);
  const isMarried: Expression = new AndExpression(julie, marrie);